#include "BlackJackManager.h"




CBlackJackManager::CBlackJackManager(void)
{

}


CBlackJackManager::~CBlackJackManager(void)
{
}

void CBlackJackManager::DealNewGame()
{   
	bool done = false;
	int choice;

	// STEP 1 : DEAL

	UserHand.AddCard(m_cardStack.getNextCard(),true);
	UserHand.AddCard(m_cardStack.getNextCard(),true);

	std::cout << "User score at deal : " << UserHand.computeScore() << std::endl;
	std::cout << "User hand: " << UserHand << std::endl;

	BankHand.AddCard(m_cardStack.getNextCard(),true);
	BankHand.AddCard(m_cardStack.getNextCard(),true);

	std::cout << "Bank score at deal : " << BankHand.computeScore() << std::endl;
	std::cout << "Bank hand: " << BankHand << std::endl;

	// STEP 2 : USER PLAYS
	while(done == false)
	{
		std::cout << std::endl;
		choice = m_UserInterface.AskForUserAction();

		if(choice == 1)
		{
			UserHand.AddCard(m_cardStack.getNextCard(),true);

			std::cout << "User new hand : " << UserHand << std::endl;
			std::cout << "User new score : " << UserHand.computeScore() << std::endl;
		}
		else if(choice == 2)
		{
			std::cout << "User final score : " << UserHand.computeScore() << std::endl;

			done = true;
		}

		if(UserHand.computeScore() > 21)
		{
			std::cout << "You got over 21, you lost !!" << std::endl;
			done = true;
		}
	}

	if(UserHand.computeScore() <= 21)
	{
		// STEP 3 : BANK PLAYS : "La banque tire a 16 et laisse a 17"
		while(BankHand.computeScore() < 17)
		{
			
			BankHand.AddCard(m_cardStack.getNextCard(),true);

			std::cout << "Bank new hand : " << BankHand << std::endl;
			std::cout << "Bank new score : " << BankHand.computeScore() << std::endl;
		}

		std::cout << std::endl;

		if(BankHand.computeScore() > 21)
		{
			std::cout << "Bank got over 21, Bank lost !!" << std::endl;
		}
		else if(UserHand.computeScore() > BankHand.computeScore())
		{
			std::cout << "You won !!" << std::endl;
		}
		else
		{
			std::cout << "You lost !!" << std::endl;
		}
	}

	std::cout << "Press Enter to finish" << std::endl;
	std::cin >> choice;
}